<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="../js/jquery-3.3.1.min.js"></script>
</head>
<body>
	<div id="greatly">
		用户id:<input type="text" id="uid" name="cc">
		<select id="mid">
			<!-- <option value="1">爱，很简单</option>
			<option value="2">假装不合适</option>
			<option value="3">爱无形</option> -->
	    </select>
		<input type="button" id="btn" value="查询">
		<input type="button" id="updbtn" value="添加">
		<div id="con">
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function(){
		$.ajax({
			"url":"../CollectionServlet?opr=list",
			"type":"get",
			"dataType":"json",
			"success":getMusic,
			"error":function(){
				alert("错误!");
			}
		});
		
		function getMusic(data){
			console.log(data,data.length);
			for(var i = 0;i<data.length;i++){
				console.log(data[i]);
				$("#mid").append("<option value="+data[i].mid+">"+data[i].mname+"</option>");
			}
		}
		
		//查询按钮
		$("#btn").click(function(){
			if($("#uid").val()!=""){
				$.ajax({
					"url":"../CollectionServlet?opr=info",
					"type":"post",
					"data":"uid="+$("#uid").val(),
					"dataType":"text",
					"success":Ok,
					"error":function(){
						alert("错误!");
					}
				});
			}else{
				alert("请填写用户id!");
			}
		});
		function Ok(data){
			$("#con").html("");
			/* console.log(data); */
			if(data == ""){$("#con").append("<p>无用户信息!</p>");return;}
			var cre = data.split(",");
			for(var i=0;i<cre.length;i++){
				$("#con").append("<p>"+cre[i]+"<span><a href='../CollectionServlet?opr=del&mid="+cre[i]+"&str="+cre+"&uid="+$("#uid").val()+"'>删除</a></span></p>");
			}
		}
		
		//添加按钮
		$("#updbtn").click(function(){
			$.ajax({
				"url":"../CollectionServlet?opr=add",
				"type":"post",
				"data":"uid="+$("#uid").val()+"&mid="+$("#mid").val(),
				"dataType":"text",
				"success":addNews,
				"error":function(){
					alert("出错!");
				}
			});
		});
		function addNews(data){
			
		}
		
	});
</script>
</html>